<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="计算机,zookeeper," />





  <link rel="alternate" href="/atom.xml" title="学不可以已" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/uploads/favicon.ico?v=5.1.2" />






<meta name="description" content="zookeeper概述什么是zookpeer zookpeer是一个项目协调框架，分布式应用可以基于它实现同步服务。  zookpeer可以做什么 为分布式应用提供集群协调服务 为客户端保存数据，提供监听 具体案例如：Hadoop2.0,使用Zookeeper的事件处理确保整个集群只有一个活跃的NameNode,存储配置信息等.HBase,使用Zookeeper的事件处理确保整个集群只有一个HMa">
<meta name="keywords" content="计算机,zookeeper">
<meta property="og:type" content="article">
<meta property="og:title" content="zookeeper">
<meta property="og:url" content="http://eregg.com/2016/11/22/zookeeper/index.html">
<meta property="og:site_name" content="学不可以已">
<meta property="og:description" content="zookeeper概述什么是zookpeer zookpeer是一个项目协调框架，分布式应用可以基于它实现同步服务。  zookpeer可以做什么 为分布式应用提供集群协调服务 为客户端保存数据，提供监听 具体案例如：Hadoop2.0,使用Zookeeper的事件处理确保整个集群只有一个活跃的NameNode,存储配置信息等.HBase,使用Zookeeper的事件处理确保整个集群只有一个HMa">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-21T18:14:58.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="zookeeper">
<meta name="twitter:description" content="zookeeper概述什么是zookpeer zookpeer是一个项目协调框架，分布式应用可以基于它实现同步服务。  zookpeer可以做什么 为分布式应用提供集群协调服务 为客户端保存数据，提供监听 具体案例如：Hadoop2.0,使用Zookeeper的事件处理确保整个集群只有一个活跃的NameNode,存储配置信息等.HBase,使用Zookeeper的事件处理确保整个集群只有一个HMa">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://eregg.com/2016/11/22/zookeeper/"/>





  <title>zookeeper | 学不可以已</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?5f1629a8f7280df347a90a49b56b2b49";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">学不可以已</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">青，取之于蓝，而青于蓝</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://eregg.com/2016/11/22/zookeeper/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="eregg">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学不可以已">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">zookeeper</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-11-22T09:40:44+08:00">
                2016-11-22
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="zookeeper概述"><a href="#zookeeper概述" class="headerlink" title="zookeeper概述"></a><a href="#zookeeper概述" title="zookeeper概述"></a>zookeeper概述</h4><h5 id="什么是zookpeer"><a href="#什么是zookpeer" class="headerlink" title="什么是zookpeer"></a><a href="#什么是zookpeer" title="什么是zookpeer"></a>什么是zookpeer</h5><blockquote>
<p>zookpeer是一个项目协调框架，分布式应用可以基于它实现同步服务。</p>
</blockquote>
<h5 id="zookpeer可以做什么"><a href="#zookpeer可以做什么" class="headerlink" title="zookpeer可以做什么"></a><a href="#zookpeer可以做什么" title="zookpeer可以做什么"></a>zookpeer可以做什么</h5><blockquote>
<p>为分布式应用提供集群协调服务</p>
<p>为客户端保存数据，提供监听</p>
<p>具体案例如：<br>Hadoop2.0,使用Zookeeper的事件处理确保整个集群只有一个活跃的NameNode,存储配置信息等.<br>HBase,使用Zookeeper的事件处理确保整个集群只有一个HMaster,察觉HRegionServer联机和宕机,存储访问控制列表等.</p>
</blockquote>
<h5 id="zookpeer集群机制"><a href="#zookpeer集群机制" class="headerlink" title="zookpeer集群机制"></a><a href="#zookpeer集群机制" title="zookpeer集群机制"></a>zookpeer集群机制</h5><blockquote>
<p>半数机制：集群中半数以上机器存活，集群可用。</p>
</blockquote>
<h4 id="安装zookpeer"><a href="#安装zookpeer" class="headerlink" title="安装zookpeer"></a><a href="#安装zookpeer" title="安装zookpeer"></a>安装zookpeer</h4><h5 id="机器部署"><a href="#机器部署" class="headerlink" title="机器部署"></a><a href="#机器部署" title="机器部署"></a>机器部署</h5><blockquote>
<p>安装到3台虚拟机上</p>
</blockquote>
<h5 id="上传"><a href="#上传" class="headerlink" title="上传"></a><a href="#上传" title="上传"></a>上传</h5><blockquote>
<p>使用上传工具将zookeeper-3.4.5.tar.gz上传至其中一台服务器（等配置完成后再分发给其他机器）</p>
</blockquote>
<h5 id="解压"><a href="#解压" class="headerlink" title="解压"></a><a href="#解压" title="解压"></a>解压</h5><figure class="highlight stylus"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ tar -zxvf zookeeper-<span class="number">3.4</span>.<span class="number">5</span><span class="selector-class">.tar</span><span class="selector-class">.gz</span> -C ~/app/</div></pre></td></tr></table></figure>

<h5 id="修改配置文件"><a href="#修改配置文件" class="headerlink" title="修改配置文件"></a><a href="#修改配置文件" title="修改配置文件"></a>修改配置文件</h5><figure class="highlight awk"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">cd ~<span class="regexp">/app/</span>zookeeper-<span class="number">3.4</span>.<span class="number">5</span><span class="regexp">/conf/</span></div><div class="line">cp zoo_sample.cfg zoo.cfg</div><div class="line">vi zoo.cfg</div><div class="line"><span class="comment">#添加内容</span></div><div class="line">dataDir=<span class="regexp">/root/</span>app<span class="regexp">/zookeeper-3.4.5/</span>data</div><div class="line">dataLogDir=<span class="regexp">/root/</span>app<span class="regexp">/zookeeper-3.4.5/</span>log  (可选)</div><div class="line">server.<span class="number">1</span>= server01:<span class="number">2888</span>:<span class="number">3888</span> (心跳端口、数据端口)</div><div class="line">server.<span class="number">2</span>= server02:<span class="number">2888</span>:<span class="number">3888</span></div><div class="line">server.<span class="number">3</span>= server03:<span class="number">2888</span>:<span class="number">3888</span></div></pre></td></tr></table></figure><br>&gt; 创建文件夹mkdir  /root/app/zookeeper-3.4.5/data<br>&gt;<br>&gt; 在data文件夹下新建myid文件，myid的文件内容为<br><figure class="highlight lsl"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">echo <span class="number">1</span> &gt; /root/app/ zookeeper<span class="number">-3.4</span><span class="number">.5</span>/data/myid</div></pre></td></tr></table></figure>

<h5 id="将配置好的安装包分发到其他机器上"><a href="#将配置好的安装包分发到其他机器上" class="headerlink" title="将配置好的安装包分发到其他机器上"></a><a href="#将配置好的安装包分发到其他机器上" title="将配置好的安装包分发到其他机器上"></a>将配置好的安装包分发到其他机器上</h5><figure class="highlight groovy"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">scp -r <span class="regexp">/root/</span>app<span class="regexp">/zookeeper-3.4.5/</span> <span class="string">server02:</span><span class="regexp">/root/</span>app/</div><div class="line">scp -r <span class="regexp">/root/</span>app<span class="regexp">/zookeeper-3.4.5/</span> <span class="string">server03:</span><span class="regexp">/root/</span>app/</div></pre></td></tr></table></figure>

<h5 id="修改其他机器的配置文件"><a href="#修改其他机器的配置文件" class="headerlink" title="修改其他机器的配置文件"></a><a href="#修改其他机器的配置文件" title="修改其他机器的配置文件"></a>修改其他机器的配置文件</h5><blockquote>
<p>到server02上：修改myid为：2</p>
<figure class="highlight lsl"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">echo <span class="number">2</span> &gt; /root/app/zookeeper<span class="number">-3.4</span><span class="number">.5</span>/data/myid</div></pre></td></tr></table></figure><br>到server03上：修改myid为：3<br><figure class="highlight lsl"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">echo <span class="number">3</span> &gt; /root/app/zookeeper<span class="number">-3.4</span><span class="number">.5</span>/data/myid</div></pre></td></tr></table></figure>

</blockquote>
<h5 id="启动zookeeper"><a href="#启动zookeeper" class="headerlink" title="启动zookeeper"></a><a href="#启动zookeeper" title="启动zookeeper"></a>启动zookeeper</h5><blockquote>
<p>先在各台机器上关闭防火墙</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="attribute">service</span>   iptables  stop</div><div class="line">chkconfig  iptables  <span class="literal">off</span></div></pre></td></tr></table></figure><br>到每一台服务器上启动zk的服务节点<br><figure class="highlight awk"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="regexp">/root/</span>app<span class="regexp">/zookeeper-3.4.5/</span>bin<span class="regexp">/zkServer.sh start</span></div></pre></td></tr></table></figure>

</blockquote>
<h5 id="查看集群状态"><a href="#查看集群状态" class="headerlink" title="查看集群状态"></a><a href="#查看集群状态" title="查看集群状态"></a>查看集群状态</h5><ol>
<li><p>jps（查看进程）</p>
<figure class="highlight lsl"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@server01 zookeeper<span class="number">-3.4</span><span class="number">.5</span>]# jps</div><div class="line"><span class="number">1837</span> QuorumPeerMain</div><div class="line"><span class="number">2113</span> Jps</div></pre></td></tr></table></figure>
</li>
<li><p>zkServer.sh status（查看集群状态，主从信息）</p>
<figure class="highlight dts"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@server01 zookeeper<span class="number">-3.4</span><span class="number">.5</span>]<span class="meta"># ./bin/zkServer.sh status</span></div><div class="line">JMX enabled by default</div><div class="line">Using config: <span class="meta-keyword">/root/</span>app/zookeeper<span class="number">-3.4</span><span class="number">.5</span><span class="meta-keyword">/bin/</span>..<span class="meta-keyword">/conf/</span>zoo.cfg</div><div class="line"><span class="symbol">Mode:</span> follower</div></pre></td></tr></table></figure>

</li>
</ol>
<h4 id="zookeeper的结构和命令"><a href="#zookeeper的结构和命令" class="headerlink" title="zookeeper的结构和命令"></a><a href="#zookeeper的结构和命令" title="zookeeper的结构和命令"></a>zookeeper的结构和命令</h4><h5 id="zookeeper数据结构"><a href="#zookeeper数据结构" class="headerlink" title="zookeeper数据结构"></a><a href="#zookeeper数据结构" title="zookeeper数据结构"></a>zookeeper数据结构</h5><ol>
<li>层次化的目录结构，命名符合常规文件系统规范</li>
<li>每个节点在zookeeper中叫做znode,并且其有一个唯一的路径标识</li>
<li>节点Znode可以包含数据和子节点</li>
<li>客户端应用可以在节点上设置监视器</li>
</ol>
<h5 id="节点类型"><a href="#节点类型" class="headerlink" title="节点类型"></a><a href="#节点类型" title="节点类型"></a>节点类型</h5><blockquote>
<p>Znode有两种类型：</p>
</blockquote>
<ol>
<li>短暂（ephemeral）（客户端断开连接，zookeeper会帮客户端把znode删除）</li>
<li>持久（persistent）（断开连接不删除）<blockquote>
<p>Znode有四种形式的目录节点（默认是persistent ）</p>
<ol>
<li>PERSISTENT</li>
<li>PERSISTENT_SEQUENTIAL（持久序列/test0000000019 ）</li>
<li>EPHEMERAL</li>
<li>EPHEMERAL_SEQUENTIAL</li>
</ol>
<p>创建znode时设置顺序标识，znode名称后会附加一个值<br>顺序号是一个单调递增的计数器，由父节点维护<br>在分布式系统中，顺序号可以被用于为所有的事件进行全局排序，这样客户端可以通过顺序号推断事件的顺序</p>
</blockquote>
</li>
</ol>
<h5 id="zookeeper特性"><a href="#zookeeper特性" class="headerlink" title="zookeeper特性"></a><a href="#zookeeper特性" title="zookeeper特性"></a>zookeeper特性</h5><ul>
<li>Zookeeper：一个leader，多个follower组成的集群</li>
<li>全局数据一致：每个server保存一份相同的数据副本，client无论连接到哪个server，数据都是一致的</li>
<li>分布式读写，更新请求转发，由leader实施</li>
<li>更新请求顺序进行，来自同一个client的更新请求按其发送顺序依次执行</li>
<li>数据更新原子性，一次数据更新要么成功，要么失败</li>
<li>实时性，在一定时间范围内，client能读到最新数据</li>
</ul>
<h5 id="zookpeer命令操作"><a href="#zookpeer命令操作" class="headerlink" title="zookpeer命令操作"></a><a href="#zookpeer命令操作" title="zookpeer命令操作"></a>zookpeer命令操作</h5><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">[zk: localhost:2181(CONNECTED) 0] <span class="keyword">help</span></div><div class="line">ZooKeeper -<span class="keyword">server</span> host:port cmd args</div><div class="line">    <span class="keyword">connect</span> host:port</div><div class="line">    <span class="keyword">get</span> <span class="keyword">path</span> [watch]</div><div class="line">    ls <span class="keyword">path</span> [watch]</div><div class="line">    <span class="keyword">set</span> <span class="keyword">path</span> <span class="keyword">data</span> [<span class="keyword">version</span>]</div><div class="line">    rmr <span class="keyword">path</span></div><div class="line">    delquota [-n|-b] <span class="keyword">path</span></div><div class="line">    quit </div><div class="line">    printwatches <span class="keyword">on</span>|<span class="keyword">off</span></div><div class="line">    <span class="keyword">create</span> [-s] [-e] <span class="keyword">path</span> <span class="keyword">data</span> acl </div><div class="line">    stat <span class="keyword">path</span> [watch]</div><div class="line">    <span class="keyword">close</span> </div><div class="line">    ls2 <span class="keyword">path</span> [watch]</div><div class="line">    history </div><div class="line">    listquota <span class="keyword">path</span></div><div class="line">    setAcl <span class="keyword">path</span> acl</div><div class="line">    getAcl <span class="keyword">path</span></div><div class="line">    <span class="keyword">sync</span> <span class="keyword">path</span></div><div class="line">    <span class="keyword">redo</span> cmdno</div><div class="line">    addauth scheme auth</div><div class="line">    <span class="keyword">delete</span> <span class="keyword">path</span> [<span class="keyword">version</span>]</div><div class="line">    setquota -n|-b val <span class="keyword">path</span></div></pre></td></tr></table></figure><br>&gt; create [-s] [-e] path data acl<br>&gt;<br>&gt; -s：sequential序列节点：会在全局维护一个序列号<br>&gt; Zk会为sequential类节点维护一个全局序列号<br>&gt;<br>&gt; -e：短暂的。 不带参数就是非短暂的<br>&gt;<br>&gt; <em>   短暂的znode（创建者客户端一旦断开连接，zk就会删除这个节点）<br>&gt; </em>   持久的znode（不管创建者客户端是否断开，znode一致存在，除非手动删除）<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">创建短暂非序列化节点：<span class="_">-e</span></div><div class="line">创建短暂序列化：<span class="_">-s</span>  –e</div><div class="line">创建持久非序列化：空</div><div class="line">创建持久序列化：<span class="_">-s</span></div></pre></td></tr></table></figure>

<ol>
<li><p>使用 ls 命令来查看当前 ZooKeeper 中所包含的内容：</p>
<figure class="highlight scheme"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[<span class="name">zk:</span> localhost:2181(<span class="name">CONNECTED</span>) <span class="number">2</span>] ls /</div><div class="line">[<span class="name">test</span>, test2, zookeeper]</div></pre></td></tr></table></figure>
</li>
<li><p>创建一个新的 znode ，使用 create /myData 。这个命令创建了一个新的 znode 节点“ zk ”以及与它关联的字符串：</p>
<figure class="highlight haxe"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[zk: <span class="type">localhost</span>:<span class="number">2181</span>(CONNECTED) <span class="number">0</span>] create /<span class="keyword">new</span><span class="type">node</span> nodedata</div><div class="line">Created /<span class="keyword">new</span><span class="type">node</span></div></pre></td></tr></table></figure>
</li>
<li><p>我们运行 get 命令来确认 znode 是否包含我们所创建的字符串：</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[zk: localhost:2181(CONNECTED) 2] get /newnode</div><div class="line">nodedata</div><div class="line">cZxid = 0x200000040</div><div class="line">ctime = Wed Jul 06 14:13:40 EDT 2016</div><div class="line">mZxid = 0x200000040</div><div class="line">mtime = Wed Jul 06 14:13:40 EDT 2016</div><div class="line">pZxid = 0x200000040</div><div class="line">cversion = 0</div><div class="line">dataVersion = 0</div><div class="line">aclVersion = 0</div><div class="line">ephemeralOwner = 0x0</div><div class="line">dataLength = 8</div><div class="line">numChildren = 0</div></pre></td></tr></table></figure>
</li>
<li><p>下面我们通过 set 命令来对 zk 所关联的字符串进行设置：</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">[zk: localhost:2181(CONNECTED) 3] set /newnode updatevalue</div><div class="line">cZxid = 0x200000040</div><div class="line">ctime = Wed Jul 06 14:13:40 EDT 2016</div><div class="line">mZxid = 0x200000041</div><div class="line">mtime = Wed Jul 06 14:14:39 EDT 2016</div><div class="line">pZxid = 0x200000040</div><div class="line">cversion = 0</div><div class="line">dataVersion = 1</div><div class="line">aclVersion = 0</div><div class="line">ephemeralOwner = 0x0</div><div class="line">dataLength = 11</div><div class="line">numChildren = 0</div></pre></td></tr></table></figure>
</li>
<li><p>下面我们将刚才创建的 znode 删除：</p>
<figure class="highlight scheme"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[<span class="name">zk:</span> localhost:2181(<span class="name">CONNECTED</span>) <span class="number">6</span>] delete /newnode</div></pre></td></tr></table></figure></li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/计算机/" rel="tag"># 计算机</a>
          
            <a href="/tags/zookeeper/" rel="tag"># zookeeper</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/11/22/signal信号/" rel="next" title="signal信号">
                <i class="fa fa-chevron-left"></i> signal信号
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/11/22/Lucene核心API/" rel="prev" title="Lucene核心API">
                Lucene核心API <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          
            <img class="site-author-image" itemprop="image"
              src="/uploads/avatar.jpg"
              alt="eregg" />
          
            <p class="site-author-name" itemprop="name">eregg</p>
            <p class="site-description motion-element" itemprop="description">青，取之于蓝，而青于蓝</p>
        </div>

        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives/">
            
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">31</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/eregg" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>GitHub</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="mailto:ereggmail@163.com" target="_blank" title="E-Mail">
                  
                    <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#zookeeper概述"><span class="nav-number">1.</span> <span class="nav-text">zookeeper概述</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#什么是zookpeer"><span class="nav-number">1.1.</span> <span class="nav-text">什么是zookpeer</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#zookpeer可以做什么"><span class="nav-number">1.2.</span> <span class="nav-text">zookpeer可以做什么</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#zookpeer集群机制"><span class="nav-number">1.3.</span> <span class="nav-text">zookpeer集群机制</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#安装zookpeer"><span class="nav-number">2.</span> <span class="nav-text">安装zookpeer</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#机器部署"><span class="nav-number">2.1.</span> <span class="nav-text">机器部署</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#上传"><span class="nav-number">2.2.</span> <span class="nav-text">上传</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#解压"><span class="nav-number">2.3.</span> <span class="nav-text">解压</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#修改配置文件"><span class="nav-number">2.4.</span> <span class="nav-text">修改配置文件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#将配置好的安装包分发到其他机器上"><span class="nav-number">2.5.</span> <span class="nav-text">将配置好的安装包分发到其他机器上</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#修改其他机器的配置文件"><span class="nav-number">2.6.</span> <span class="nav-text">修改其他机器的配置文件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#启动zookeeper"><span class="nav-number">2.7.</span> <span class="nav-text">启动zookeeper</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#查看集群状态"><span class="nav-number">2.8.</span> <span class="nav-text">查看集群状态</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#zookeeper的结构和命令"><span class="nav-number">3.</span> <span class="nav-text">zookeeper的结构和命令</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#zookeeper数据结构"><span class="nav-number">3.1.</span> <span class="nav-text">zookeeper数据结构</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#节点类型"><span class="nav-number">3.2.</span> <span class="nav-text">节点类型</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#zookeeper特性"><span class="nav-number">3.3.</span> <span class="nav-text">zookeeper特性</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#zookpeer命令操作"><span class="nav-number">3.4.</span> <span class="nav-text">zookpeer命令操作</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 &mdash; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">eregg</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动</div>

  <span class="post-meta-divider">|</span>

  <div class="theme-info">主题 &mdash; <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.2</div>


        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  

  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  








  





  

  

  

  

  

  

</body>
</html>
